{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# NONE-EARLY All RIDERS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "40832"
      ],
      "text/latex": [
       "40832"
      ],
      "text/markdown": [
       "40832"
      ],
      "text/plain": [
       "[1] 40832"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "y ~ a + c:b + b + b:a"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "y ~ a + b + c:b + a:b"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "y ~ a + b + b:c + a:b"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "import_and_maybe_install <- function(pkgs){\n",
    "    missing_packages <- character(0)\n",
    "    for(pkg in pkgs){\n",
    "        tryCatch({\n",
    "            require(pkg, character.only=TRUE ,quietly=TRUE)\n",
    "        },warning=function(err){\n",
    "            missing_packages <<- c(missing_packages,pkg)\n",
    "        })\n",
    "    }\n",
    "    if(length(missing_packages)){\n",
    "            install.packages(missing_packages)\n",
    "            sapply(missing_packages, require, character.only=TRUE,quietly=TRUE)\n",
    "    }\n",
    "    invisible(NULL)\n",
    "}\n",
    "import_and_maybe_install(c(\"data.table\", \"feather\", \"ggplot2\",\"clusterSEs\",\"formula.tools\",\"estimatr\",\"doAzureParallel\"))\n",
    "Sys.getpid()\n",
    "\n",
    "\n",
    "\n",
    "(fmla <- y ~ a + c:b + b + b:a)\n",
    "\n",
    "# \"update\" the fomula with no actual changes\n",
    "(fmla1 <- update(fmla,~.)) # y ~ a + b + c:b + a:b)\n",
    "\n",
    "# \"update\" the fomula with no actual changes AGAIN\n",
    "update(fmla1,~.) # y ~ a + b + b:c + a:b\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "if(FALSE){\n",
    "    remove.packages(\"clusterSEs\")\n",
    "    devtools::install(\"~/clusterSEs\")\n",
    "    library(clusterSEs)\n",
    "    cat(\"DONE\\n\")\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "DATA_DIR <- \"~/connector/20200226/analytic_datasets\"\n",
    "\n",
    "commute_ride_data <- read_feather( file.path(DATA_DIR,\"commute_ride_data.feather\"))\n",
    "setDT(commute_ride_data)\n",
    "\n",
    "commute_ride_data[,I405HOV:=0 + (date > as.Date(\"2015-09-25\"))]\n",
    "\n",
    "# FACTOR VARIABLES\n",
    "stopifnot(commute_ride_data[,class(fAid) == \"factor\"]) # rider id\n",
    "stopifnot(commute_ride_data[,class(fDate) == \"factor\"]) # date id\n",
    "\n",
    "#route_field <- sprintf(\"route_%s_10_ride\",1:21)\n",
    "\n",
    "# CALCULATE FAVORITE ROUTE\n",
    "commute_ride_data$favorite_route <- apply(\n",
    "    as.matrix(commute_ride_data[,sprintf(\"route_%s_10_ride\",1:21),with=FALSE]),\n",
    "    1,\n",
    "    function(x){\n",
    "        routes = which(x == max(x))\n",
    "        if(length(routes) == 1){\n",
    "            routes\n",
    "        }else{\n",
    "            sample(routes,1)\n",
    "        }\n",
    "    })\n",
    "\n",
    "commute_ride_data[, f_favorite_route:= as.factor(favorite_route) ]\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CALCULATE FAVORITE ROUTE\n",
    "commute_ride_data$favorite_route <- apply(\n",
    "    as.matrix(commute_ride_data[,sprintf(\"route_%s_10_ride\",1:21),with=FALSE]),\n",
    "    1,\n",
    "    function(x){\n",
    "        routes = which(x == max(x))\n",
    "        if(length(routes) == 1){\n",
    "            routes\n",
    "        }else{\n",
    "            sample(routes,1)\n",
    "        }\n",
    "    })\n",
    "\n",
    "commute_ride_data[, f_favorite_route:= as.factor(favorite_route) ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FILTER on {{NOT}} EARLY RIDERS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of Early Riders"
     ]
    },
    {
     "data": {
      "text/html": [
       "3908"
      ],
      "text/latex": [
       "3908"
      ],
      "text/markdown": [
       "3908"
      ],
      "text/plain": [
       "[1] 3908"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full Data"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>3354470</td><td>805199 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 3354470 & 805199 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 3354470 | 805199  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 3354470 805199"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Late riders only"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1562314</td><td>164677 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 1562314 & 164677 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 1562314 | 164677  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 1562314 164677"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "dates = commute_ride_data[,.N,keyby=.(date,fDate)]\n",
    "MAX_DATE = dates[15,date]\n",
    "\n",
    "early_riders = commute_ride_data[date <= MAX_DATE & did_ride,1,keyby=aid][,V1:=NULL]\n",
    "cat(\"Number of Early Riders\")\n",
    "early_riders[,.N]\n",
    "\n",
    "cat(\"Full Data\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "setkey(commute_ride_data,aid)\n",
    "commute_ride_data = commute_ride_data[!early_riders]\n",
    "\n",
    "cat(\"Late riders only\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Log in and maybe create the cluster"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "================================================================================\n",
      "Batch Account: msftconnectorpaper\n",
      "Batch Account Url: https://msftconnectorpaper.westus2.batch.azure.com\n",
      "Storage Account: msftconnectorpaper\n",
      "Storage Account Url: https://msftconnectorpaper.blob.core.windows.net\n",
      "================================================================================\n",
      "Your credentials have been successfully set.\n",
      "================================================================================\n",
      "Name: msftconnectorpaper\n",
      "Configuration:\n",
      "\tDocker Image: rocker/tidyverse:3.4.1\n",
      "\tMaxTasksPerNode: 3\n",
      "\tNode Size: Standard_D13_v2\n",
      "cranPackages: \n",
      "\tdoParallel; data.table; feather; formula.tools; \n",
      "githubPackages: \n",
      "\tAzure/doAzureParallel; jdthorpe/clusterSEs; \n",
      "Scale:\n",
      "\tAutoscale Formula: QUEUE\n",
      "\tDedicated:\n",
      "\t\tMin: 0\n",
      "\t\tMax: 0\n",
      "\tLow Priority:\n",
      "\t\tMin: 62\n",
      "\t\tMax: 150\n",
      "================================================================================\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Warning message in self$client$extractAzureResponse(response, content):\n",
      "\"Conflict (HTTP 409).\"\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The specified cluster 'msftconnectorpaper' already exists. Cluster 'msftconnectorpaper' will be used.\n",
      "Your cluster has been registered.\n",
      "Dedicated Node Count: 0\n",
      "Low Priority Node Count: 62\n"
     ]
    }
   ],
   "source": [
    "setCredentials(\"Connector/creds.json\")\n",
    "cluster <- makeCluster(\"Connector/config.json\",wait=FALSE)\n",
    "registerDoAzureParallel(cluster)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "it's all good, there are 186 workers\n"
     ]
    }
   ],
   "source": [
    "# Check if the workers are ready to do some work\n",
    "n_workers <- getDoParWorkers()\n",
    "stopifnot(n_workers>0)\n",
    "cat(sprintf(\"it's all good, there are %s workers\\n\",n_workers))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Dictionary\n",
    "\n",
    "Each record represents one rider commute opportunty (rider / date / commute).\n",
    "\n",
    "**Note that** there is one record for each commute / data for every rider \n",
    "*After their first ride date*.  This is because the choice to ride (`did_ride`) \n",
    "is conditioned on the rider's history of riding, and which is not available \n",
    "on thier first ride.\n",
    "\n",
    "#### Identifiers\n",
    "* **aid**: Rider number (anonomyzed Numeric)\n",
    "* **fAid**: Rider number (anonomyzed Factor)\n",
    "* **date**: Date of the ride (as Date)\n",
    "* **fDate**: Date of the ride (as Factor)\n",
    "* **AfternoonId**: Function of Date, only true for Route 5\n",
    "\n",
    "#### Main outcome / predictor\n",
    "* **did_ride**: Did the rider ride on this date?\n",
    "* **imputed_new_buses**: The weighted average of the fraction of new busses \n",
    "     on the routes the rider took on the last (up to) 10 trips\n",
    "\n",
    "#### Time since last ride\n",
    "* **commutes_since_last_ride**: Number of commutes since rider's last ride (numeric; range 1 - 461)\n",
    "* **f_commutes_since_last_ride**: Number of commutes since rider's last ride (factor; range \"1\" - \"40+\")\n",
    "     \n",
    "#### Date based indicators\n",
    "* **SR520WBHOV**: SR 520 West Bound is open (Function of the date)\n",
    "* **SR520EBHOV**: SR 520 East Bound is open (Function of the date)\n",
    "* **I405HOV**: Is a 405 HOV is open (Function of the date )\n",
    "* **Route5Expansion**: Route 5 expanded (Function of Date )\n",
    "\n",
    "#### Features based on the rider's history\n",
    "* **route_X_10_ride** (e.g. `route_3_10_ride`):  Fraction of the rider's last 10 rides that were taken on route X\n",
    "* **is_peak_10_ride**: Fraction of the rider's last 10 rides that were taken **during peak traffic**\n",
    "* **IsESOther_10_ride**: Fraction of the rider's last 10 rides that were taken on **EastSide (other) routes**\n",
    "* **IsRouteSeattle_10_ride**: Fraction of the rider's last 10 rides that were taken on **Seattle Routes**\n",
    "* **Is405North_10_ride**: Fraction of the rider's last 10 rides that were taken on **I 405 North Routes**\n",
    "* **IsCoach_10_ride**: Fraction of the rider's last 10 rides that were taken on  **Coach (as opposed to shuttle) busses**\n",
    "* **first_stop_10_ride**: Fraction of the rider's last 10 rides that were taken from **the last AM stop**\n",
    "* **last_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on  **the first AM stop**\n",
    "* **single_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on **a Single Stop Route**\n",
    "* **vehicle_is_new_10_ride**: Fraction of the rider's last 10 rides that were taken on **a new vehicle**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Handy Utility function for fitting models and gathering summary statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' A cute little function for fitting a model and pulling out the headline statistics\n",
    "#'\n",
    "#' @param data A dataset for fitting the model\n",
    "#' @param model A number for identifying the model in a table (these second field in the \"coef\" output)\n",
    "#' @param lhs The left hand side of the model (as a string)\n",
    "#' @param predictors The effects of interested.  Specifically these are the effects that will be pulled out in the summary table\n",
    "#' @param adjust_for The fixed effects that will be included in the right hand side but not pulled out into the summar table\n",
    "#'\n",
    "#' @return A list containing the glm model (`$model`), and a matrix of interesting statistics from the\n",
    "#'       various models (`$coef`)\n",
    "\n",
    "fit_ridership_logit_models <- function(data,\n",
    "                                        model=1,\n",
    "                                        lhs=\"did_ride\",\n",
    "                                        predictors=\"new_fraction_10day\",\n",
    "                                        adjust_for=\"fDate\",# up to 231 levels\n",
    "                                        cluster_on = ~ f_favorite_route,\n",
    "                                        quick=FALSE,\n",
    "                                        seed = 10101,\n",
    "                                        boot.reps=1001,\n",
    "                                        granularity=\"\"){\n",
    "\n",
    "    begin = Sys.time()\n",
    "    cat(sprintf(\"Starting at %s\\n\",begin))\n",
    "    \n",
    "    # build and test the formula \n",
    "    (FMLA <- formula(paste(lhs,'~',paste(c(sort(adjust_for),sort(predictors)),collapse=' + '))))\n",
    "    (current_terms <- attr(terms(FMLA),\"term.labels\"))\n",
    "    \n",
    "    if(!all(predictors %in% current_terms)){\n",
    "        cat(sprintf(\"CURRENT TERMS: %s\\n\",current_terms))\n",
    "        cat(\"\\n\")\n",
    "        cat(sprintf(\"PREDICTORS: %s\\n\",predictors))\n",
    "        cat(\"\\n\")\n",
    "        \n",
    "        will_be_dropped <- setdiff(predictors,current_terms)\n",
    "        will_appear <- setdiff(current_terms,c(predictors,adjust_for))\n",
    "        stop(sprintf(\"The following terms will be are not robust to <<string parsing>>:\\n%s\\n\\nPlease Update them as follows:\\n%s\\n \",\n",
    "            paste0(will_be_dropped,collapse=\"\\n\"),\n",
    "            paste0(will_appear,collapse=\"\\n\")))\n",
    "    }\n",
    "    \n",
    "    UPDATED = update(FMLA,~.)\n",
    "    (updated_terms <- attr(terms(UPDATED),\"term.labels\"))\n",
    "    if(!(all(updated_terms %in% current_terms))){\n",
    "        \n",
    "        (will_be_dropped <- setdiff(current_terms,updated_terms))\n",
    "        (will_appear <- setdiff(updated_terms,current_terms))\n",
    "        \n",
    "        stop(sprintf(\"The following terms will be are not robust to <<model updates>>:\\n%s\\n\\nPlease Update them as follows:\\n%s\\n \",\n",
    "            paste0(will_be_dropped,collapse=\"\\n\"),\n",
    "            paste0(will_appear,collapse=\"\\n\")))\n",
    "    }\n",
    "    \n",
    "    quick_N <- 1e5\n",
    "    if(quick & data[,.N] > quick_N)\n",
    "        data <- data[sample(.N,quick_N)]\n",
    "\n",
    "    # FIT THE OLS MODELS\n",
    "\n",
    "    cat(sprintf(\"Starting the base glm (OLS) model...at %s\\n\",round(Sys.time() - begin,3)))\n",
    "    start <- Sys.time()\n",
    "    LM <- glm(FMLA, data = data) # required for the wild bootstrap\n",
    "\n",
    "    cat(sprintf(\"Finished the base glm (OLS) model... in %s seconds\\n\",round(Sys.time() - start,3)))\n",
    "\n",
    "    # SUMMARY OF THE OLS MODEL\n",
    "    cat(sprintf(\"Starting the summary()...at %s\\n\",round(Sys.time() - begin,3)))\n",
    "    start <- Sys.time()\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "    cat(\"Model \",model,\":\")\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "\n",
    "    cat(\"\\n\\nCoefficients from Linear model (adjust_for effects omitted):\\n\")\n",
    "\n",
    "    # catch the re-ordering of interaction terms introduced by the update(form,dev.new ~ .) call in cluster.wild.glm\n",
    "    tryCatch({\n",
    "        print(coef(summary(LM))[predictors,])    \n",
    "    },error = function(err){\n",
    "        model_coef = dimnames(coef(summary(LM)))[[1]]\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "            print(FMLA)\n",
    "            print(coef(summary(LM)))\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "        cat(\"Missing coefficients:\\n\",\n",
    "            predictors[! predictors %in% model_coef])\n",
    "        cat(\"\\n\\nAvailable coefficients:\\n\")\n",
    "\n",
    "        print(model_coef)\n",
    "        stop(err)\n",
    "    })\n",
    "        cat(sprintf(\"Finished the summary in %s seconds\\n\",round(Sys.time() - start,3)))\n",
    "\n",
    "    # DO THE WILD BOOTSTRAP\n",
    "    # set.seed(10101)\n",
    "    # cl <-cluster.wild.glm(LM, dat = data, cluster = ~ factor(favorite_route), boot.reps = boot.reps, report=FALSE )\n",
    "    gc()\n",
    "    cat(sprintf(\"Starting the wild bootstraps...at %s\\n\",round(Sys.time() - begin,3)))\n",
    "    cl <-cluster.wild.glm(LM,\n",
    "                          dat = data,\n",
    "                          cluster = cluster_on,\n",
    "                          boot.reps = ifelse(quick,3,boot.reps),\n",
    "                          report=FALSE,\n",
    "                          dopar=TRUE,\n",
    "                          seed=seed)\n",
    "\n",
    "    cat(\"Finished the wild bootstraps...\\n\")\n",
    "        cat(sprintf(\"Finished wild bootstraps in %s seconds\\n\",round(Sys.time() - start,3)))\n",
    "    # MAKE THE PRETTY OUTPUT\n",
    "    CI = rbind(cl$ci[predictors,])\n",
    "\n",
    "    out <- cbind(model=model,\n",
    "                        \"OLS Estimate\"=coef(summary(LM))[predictors,\"Estimate\"],\n",
    "                        \"BS p-value\"=cl$p.values[predictors,],\n",
    "                        CI,\n",
    "                        N=data[,.N],\n",
    "                        granularity=granularity)\n",
    "    dimnames(out)[[1]] <- predictors\n",
    "\n",
    "    rm(LM,cl); gc() # alas...\n",
    "    # dimnames(out)[[1]] <- predictors\n",
    "    return(out)\n",
    "\n",
    "} "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for table 2\n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Starting at 2020-07-04 10:29:34Starting the base glm (OLS) model...at 0.079\n",
      "Finished the base glm (OLS) model... in 5.123 seconds\n",
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 5.245727e-02  1.482523e-03  3.538377e+01 5.359494e-274 \n",
      "Finished the summary in 0.398 seconds\n",
      "Starting the wild bootstraps...at 5.969\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704173004\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished wild bootstraps in 5.529 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                           </td><td>0.0524572663881309          </td><td>0                           </td><td>0.038550490289414           </td><td>0.0663640424868477          </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                & 0.0524572663881309               & 0                                & 0.038550490289414                & 0.0663640424868477               & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                            | 0.0524572663881309           | 0                            | 0.038550490289414            | 0.0663640424868477           | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model OLS Estimate       BS p-value CI lower         \n",
       "imputed_new_buses 1     0.0524572663881309 0          0.038550490289414\n",
       "                  CI higher          N      granularity                 \n",
       "imputed_new_buses 0.0663640424868477 689102 rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model1_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...\n",
      "Starting at 2020-07-03 17:26:00Starting the base glm (OLS) model...at 0.075\n",
      "Finished the base glm (OLS) model... in 5.786 seconds\n",
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.04747585 0.001988469 23.875580\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.01098692 0.002894419  3.795898\n",
      "                                              Pr(>|t|)\n",
      "imputed_new_buses                        6.183669e-126\n",
      "imputed_new_buses:IsRouteSeattle_10_ride  1.471224e-04\n",
      "Finished the summary in 0.389 seconds\n",
      "Starting the wild bootstraps...at 6.663\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704002632\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results..... Completed.\n",
      "Finished wild bootstraps in 5.745 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                           </td><td>0.0474758459404773          </td><td>0                           </td><td>0.0311320290466682          </td><td>0.0638196628342865          </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                           </td><td>0.0109869187882225          </td><td>0.417582417582418           </td><td>-0.0197846829838237         </td><td>0.0417585205602686          </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                                & 0.0474758459404773               & 0                                & 0.0311320290466682               & 0.0638196628342865               & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                & 0.0109869187882225               & 0.417582417582418                & -0.0197846829838237              & 0.0417585205602686               & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                            | 0.0474758459404773           | 0                            | 0.0311320290466682           | 0.0638196628342865           | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                            | 0.0109869187882225           | 0.417582417582418            | -0.0197846829838237          | 0.0417585205602686           | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model OLS Estimate      \n",
       "imputed_new_buses                        2     0.0474758459404773\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.0109869187882225\n",
       "                                         BS p-value        CI lower           \n",
       "imputed_new_buses                        0                 0.0311320290466682 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.417582417582418 -0.0197846829838237\n",
       "                                         CI higher          N     \n",
       "imputed_new_buses                        0.0638196628342865 689102\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0417585205602686 689102\n",
       "                                         granularity                 \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\\n\")\n",
    "(table2_model2 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c( \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...\n",
      "Starting at 2020-07-03 17:31:51Starting the base glm (OLS) model...at 0.068\n",
      "Finished the base glm (OLS) model... in 2.26 seconds\n",
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.04431726 0.002618298 16.925983\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.02048558 0.004090306  5.008325\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        3.095978e-64\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 5.493612e-07\n",
      "Finished the summary in 0.179 seconds\n",
      "Starting the wild bootstraps...at 2.966\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704003206\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results... Completed.\n",
      "Finished wild bootstraps in 3.265 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                        </td><td>0.0443172587068115                                       </td><td>0.00199800199800204                                      </td><td>0.0222469120055949                                       </td><td>0.0663876054080281                                       </td><td>307332                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                        </td><td>0.020485581140182                                        </td><td>0.252747252747253                                        </td><td>-0.0196612739494071                                      </td><td>0.0606324362297711                                       </td><td>307332                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                                                             & 0.0443172587068115                                            & 0.00199800199800204                                           & 0.0222469120055949                                            & 0.0663876054080281                                            & 307332                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                             & 0.020485581140182                                             & 0.252747252747253                                             & -0.0196612739494071                                           & 0.0606324362297711                                            & 307332                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                                                         | 0.0443172587068115                                        | 0.00199800199800204                                       | 0.0222469120055949                                        | 0.0663876054080281                                        | 307332                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                         | 0.020485581140182                                         | 0.252747252747253                                         | -0.0196612739494071                                       | 0.0606324362297711                                        | 307332                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model OLS Estimate      \n",
       "imputed_new_buses                        3     0.0443172587068115\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     0.020485581140182 \n",
       "                                         BS p-value         \n",
       "imputed_new_buses                        0.00199800199800204\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.252747252747253  \n",
       "                                         CI lower            CI higher         \n",
       "imputed_new_buses                        0.0222469120055949  0.0663876054080281\n",
       "imputed_new_buses:IsRouteSeattle_10_ride -0.0196612739494071 0.0606324362297711\n",
       "                                         N     \n",
       "imputed_new_buses                        307332\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 307332\n",
       "                                         granularity                                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\\n\")\n",
    "(table2_model3_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (first_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c( \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; First stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...\n",
      "Starting at 2020-07-03 17:35:10Starting the base glm (OLS) model...at 0.069\n",
      "Finished the base glm (OLS) model... in 3.727 seconds\n",
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                            Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.049870653 0.002234372 22.319759\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.008433686 0.003462552  2.435685\n",
      "                                              Pr(>|t|)\n",
      "imputed_new_buses                        2.711964e-110\n",
      "imputed_new_buses:IsRouteSeattle_10_ride  1.486400e-02\n",
      "Finished the summary in 0.264 seconds\n",
      "Starting the wild bootstraps...at 4.362\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704003532\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results. Completed.\n",
      "Finished wild bootstraps in 4.17 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                       </td><td>0.0498706527113715                                      </td><td>0                                                       </td><td>0.0309825481407093                                      </td><td>0.0687587572820337                                      </td><td>470230                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                       </td><td>0.00843368561557272                                     </td><td>0.552447552447553                                       </td><td>-0.0213587721907368                                     </td><td>0.0382261434218822                                      </td><td>470230                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                                                            & 0.0498706527113715                                           & 0                                                            & 0.0309825481407093                                           & 0.0687587572820337                                           & 470230                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                            & 0.00843368561557272                                          & 0.552447552447553                                            & -0.0213587721907368                                          & 0.0382261434218822                                           & 470230                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                                                        | 0.0498706527113715                                       | 0                                                        | 0.0309825481407093                                       | 0.0687587572820337                                       | 470230                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                        | 0.00843368561557272                                      | 0.552447552447553                                        | -0.0213587721907368                                      | 0.0382261434218822                                       | 470230                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model OLS Estimate       \n",
       "imputed_new_buses                        4     0.0498706527113715 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.00843368561557272\n",
       "                                         BS p-value        CI lower           \n",
       "imputed_new_buses                        0                 0.0309825481407093 \n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.552447552447553 -0.0213587721907368\n",
       "                                         CI higher          N     \n",
       "imputed_new_buses                        0.0687587572820337 470230\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.0382261434218822 470230\n",
       "                                         granularity                                             \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\\n\")\n",
    "(table2_model4_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (last_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",  \"f_commutes_since_last_ride\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Last stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...\n",
      "Starting at 2020-07-03 17:39:24Starting the base glm (OLS) model...at 0.059\n",
      "Finished the base glm (OLS) model... in 2.791 seconds\n",
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 5.944159e-02  2.278223e-03  2.609120e+01 6.151765e-150 \n",
      "Finished the summary in 0.267 seconds\n",
      "Starting the wild bootstraps...at 3.44\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704003942\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results... Completed.\n",
      "Finished wild bootstraps in 3.514 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                     </td><td>0.0594415944093541                                    </td><td>0.00799200799200794                                   </td><td>0.0251018148699373                                    </td><td>0.093781373948771                                     </td><td>395760                                                </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 5                                                          & 0.0594415944093541                                         & 0.00799200799200794                                        & 0.0251018148699373                                         & 0.093781373948771                                          & 395760                                                     & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 5                                                      | 0.0594415944093541                                     | 0.00799200799200794                                    | 0.0251018148699373                                     | 0.093781373948771                                      | 395760                                                 | rider/date/commute [Pre-HOV; Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model OLS Estimate       BS p-value         \n",
       "imputed_new_buses 5     0.0594415944093541 0.00799200799200794\n",
       "                  CI lower           CI higher         N     \n",
       "imputed_new_buses 0.0251018148699373 0.093781373948771 395760\n",
       "                  granularity                                           \n",
       "imputed_new_buses rider/date/commute [Pre-HOV; Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\\n\")\n",
    "(table2_model5_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride >= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",  \"f_commutes_since_last_ride\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...\n",
      "Starting at 2020-07-03 17:42:58Starting the base glm (OLS) model...at 0.055\n",
      "Finished the base glm (OLS) model... in 1.856 seconds\n",
      "\n",
      "===============================================\n",
      "Model  6 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 4.592108e-02  1.885642e-03  2.435302e+01 7.262503e-131 \n",
      "Finished the summary in 0.176 seconds\n",
      "Starting the wild bootstraps...at 2.564\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704004312\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results. Completed.\n",
      "Finished wild bootstraps in 2.88 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>6                                                         </td><td>0.0459210760208515                                        </td><td>0                                                         </td><td>0.0320891442648015                                        </td><td>0.0597530077769016                                        </td><td>294658                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 6                                                              & 0.0459210760208515                                             & 0                                                              & 0.0320891442648015                                             & 0.0597530077769016                                             & 294658                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 6                                                          | 0.0459210760208515                                         | 0                                                          | 0.0320891442648015                                         | 0.0597530077769016                                         | 294658                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model OLS Estimate       BS p-value CI lower          \n",
       "imputed_new_buses 6     0.0459210760208515 0          0.0320891442648015\n",
       "                  CI higher          N     \n",
       "imputed_new_buses 0.0597530077769016 294658\n",
       "                  granularity                                               \n",
       "imputed_new_buses rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\\n\")\n",
    "(table2_model6_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride <= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",  \"f_commutes_since_last_ride\"),\n",
    "                            model=6,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Non-Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 2 Summary Statistics \n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "ename": "ERROR",
     "evalue": "Error in rbind(table2_model1_pre_HOV, table2_model2, table2_model3_pre_HOV, : object 'table2_model1_pre_HOV' not found\n",
     "output_type": "error",
     "traceback": [
      "Error in rbind(table2_model1_pre_HOV, table2_model2, table2_model3_pre_HOV, : object 'table2_model1_pre_HOV' not found\nTraceback:\n",
      "1. rbind(table2_model1_pre_HOV, table2_model2, table2_model3_pre_HOV, \n .     table2_model4_pre_HOV, table2_model5_pre_HOV, table2_model6_pre_HOV)"
     ]
    }
   ],
   "source": [
    "\n",
    "rbind( table2_model1_pre_HOV,\n",
    "       table2_model2,\n",
    "       table2_model3_pre_HOV,\n",
    "       table2_model4_pre_HOV,\n",
    "       table2_model5_pre_HOV,\n",
    "       table2_model6_pre_HOV)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 3 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-03 23:05:07Starting the base glm (OLS) model...at 0.002\n",
      "Finished the base glm (OLS) model... in 3.486 seconds\n",
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "8.183326e-03 8.165464e-04 1.002188e+01 1.223628e-23 \n",
      "Finished the summary in 1.24 seconds\n",
      "Starting the wild bootstraps...at 3.541\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704061300\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.............. Completed.\n",
      "Finished wild bootstraps in 2.484 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>1                   </td><td>0.00818332646780441 </td><td>0.000999000999000965</td><td>0.00408485239977426 </td><td>0.0122818005358346  </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 1                    & 0.00818332646780441  & 0.000999000999000965 & 0.00408485239977426  & 0.0122818005358346   & 1562314              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 1                    | 0.00818332646780441  | 0.000999000999000965 | 0.00408485239977426  | 0.0122818005358346   | 1562314              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                model OLS Estimate        BS p-value          \n",
       "post_hov:IsRouteSeattle_10_ride 1     0.00818332646780441 0.000999000999000965\n",
       "                                CI lower            CI higher          N      \n",
       "post_hov:IsRouteSeattle_10_ride 0.00408485239977426 0.0122818005358346 1562314\n",
       "                                granularity       \n",
       "post_hov:IsRouteSeattle_10_ride rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"In Progress...\")\n",
    "(table3_model1 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                        model=1,\n",
    "                        granularity=\"rider/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-04 13:06:42\n",
      "Starting the base glm (OLS) model...at 0.001\n",
      "Finished the base glm (OLS) model... in 3.589 seconds\n",
      "Starting the summary()...at 3.589\n",
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                    Estimate  Std. Error\n",
      "IsRouteSeattle_10_ride:post_hov                 0.0081188364 0.001464482\n",
      "is_peak_10_ride                                 0.0002109957 0.001204529\n",
      "is_peak_10_ride:IsRouteSeattle_10_ride          0.0085013423 0.001548632\n",
      "is_peak_10_ride:post_hov                        0.0022491907 0.001621923\n",
      "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.0002550694 0.002088084\n",
      "                                                  t value     Pr(>|t|)\n",
      "IsRouteSeattle_10_ride:post_hov                 5.5438299 2.959739e-08\n",
      "is_peak_10_ride                                 0.1751687 8.609471e-01\n",
      "is_peak_10_ride:IsRouteSeattle_10_ride          5.4895818 4.029489e-08\n",
      "is_peak_10_ride:post_hov                        1.3867433 1.655202e-01\n",
      "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.1221547 9.027765e-01\n",
      "Finished the summary in 1.182 seconds\n",
      "Starting the wild bootstraps...at 3.645\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704201443\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results...... Completed.\n",
      "Finished the wild bootstraps...\n",
      "Finished wild bootstraps in 2.677 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:post_hov</th><td>2                   </td><td>0.00811883641669418 </td><td>0.0309690309690309  </td><td>0.000844313316093389</td><td>0.015393359517295   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                   </td><td>0.000210995677427104</td><td>0.929070929070929   </td><td>-0.00618521170005434</td><td>0.00660720305490855 </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:IsRouteSeattle_10_ride</th><td>2                   </td><td>0.00850134229045719 </td><td>0.0179820179820179  </td><td>0.00159615757794212 </td><td>0.0154065270029723  </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:post_hov</th><td>2                   </td><td>0.00224919071823332 </td><td>0.46953046953047    </td><td>-0.00455513135967938</td><td>0.00905351279614601 </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:IsRouteSeattle_10_ride:post_hov</th><td>2                   </td><td>0.000255069378147556</td><td>0.942057942057942   </td><td>-0.0071018605895833 </td><td>0.00761199934587842 </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tIsRouteSeattle\\_10\\_ride:post\\_hov & 2                    & 0.00811883641669418  & 0.0309690309690309   & 0.000844313316093389 & 0.015393359517295    & 1562314              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                    & 0.000210995677427104 & 0.929070929070929    & -0.00618521170005434 & 0.00660720305490855  & 1562314              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride:IsRouteSeattle\\_10\\_ride & 2                    & 0.00850134229045719  & 0.0179820179820179   & 0.00159615757794212  & 0.0154065270029723   & 1562314              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride:post\\_hov & 2                    & 0.00224919071823332  & 0.46953046953047     & -0.00455513135967938 & 0.00905351279614601  & 1562314              & rider/date/commute  \\\\\n",
       "\tis\\_peak\\_10\\_ride:IsRouteSeattle\\_10\\_ride:post\\_hov & 2                    & 0.000255069378147556 & 0.942057942057942    & -0.0071018605895833  & 0.00761199934587842  & 1562314              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| IsRouteSeattle_10_ride:post_hov | 2                    | 0.00811883641669418  | 0.0309690309690309   | 0.000844313316093389 | 0.015393359517295    | 1562314              | rider/date/commute   |\n",
       "| is_peak_10_ride | 2                    | 0.000210995677427104 | 0.929070929070929    | -0.00618521170005434 | 0.00660720305490855  | 1562314              | rider/date/commute   |\n",
       "| is_peak_10_ride:IsRouteSeattle_10_ride | 2                    | 0.00850134229045719  | 0.0179820179820179   | 0.00159615757794212  | 0.0154065270029723   | 1562314              | rider/date/commute   |\n",
       "| is_peak_10_ride:post_hov | 2                    | 0.00224919071823332  | 0.46953046953047     | -0.00455513135967938 | 0.00905351279614601  | 1562314              | rider/date/commute   |\n",
       "| is_peak_10_ride:IsRouteSeattle_10_ride:post_hov | 2                    | 0.000255069378147556 | 0.942057942057942    | -0.0071018605895833  | 0.00761199934587842  | 1562314              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model OLS Estimate        \n",
       "IsRouteSeattle_10_ride:post_hov                 2     0.00811883641669418 \n",
       "is_peak_10_ride                                 2     0.000210995677427104\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          2     0.00850134229045719 \n",
       "is_peak_10_ride:post_hov                        2     0.00224919071823332 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 2     0.000255069378147556\n",
       "                                                BS p-value        \n",
       "IsRouteSeattle_10_ride:post_hov                 0.0309690309690309\n",
       "is_peak_10_ride                                 0.929070929070929 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.0179820179820179\n",
       "is_peak_10_ride:post_hov                        0.46953046953047  \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.942057942057942 \n",
       "                                                CI lower            \n",
       "IsRouteSeattle_10_ride:post_hov                 0.000844313316093389\n",
       "is_peak_10_ride                                 -0.00618521170005434\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.00159615757794212 \n",
       "is_peak_10_ride:post_hov                        -0.00455513135967938\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov -0.0071018605895833 \n",
       "                                                CI higher           N      \n",
       "IsRouteSeattle_10_ride:post_hov                 0.015393359517295   1562314\n",
       "is_peak_10_ride                                 0.00660720305490855 1562314\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.0154065270029723  1562314\n",
       "is_peak_10_ride:post_hov                        0.00905351279614601 1562314\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.00761199934587842 1562314\n",
       "                                                granularity       \n",
       "IsRouteSeattle_10_ride:post_hov                 rider/date/commute\n",
       "is_peak_10_ride                                 rider/date/commute\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          rider/date/commute\n",
       "is_peak_10_ride:post_hov                        rider/date/commute\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"In Progress...\")\n",
    "(table3_model2 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors= c(\"IsRouteSeattle_10_ride:post_hov\",\n",
    "                                        \"is_peak_10_ride\",\n",
    "                                        \"is_peak_10_ride:IsRouteSeattle_10_ride\",\n",
    "                                        \"is_peak_10_ride:post_hov\",\n",
    "                                        \"is_peak_10_ride:IsRouteSeattle_10_ride:post_hov\"\n",
    "                                ),\n",
    "                        model=2,\n",
    "                        adjust_for=c(\"imputed_new_buses\",\"AfternoonId\",\"fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                        granularity=\"rider/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-04 04:18:54Starting the base glm (OLS) model...at 0.071\n",
      "Finished the base glm (OLS) model... in 1.262 seconds\n",
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.029260e-02 1.176873e-03 8.745716e+00 2.220907e-18 \n",
      "Finished the summary in 0.477 seconds\n",
      "Starting the wild bootstraps...at 1.284\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704112155\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished wild bootstraps in 1.08 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>3                                              </td><td>0.0102925974473447                             </td><td>0                                              </td><td>0.00658240204617865                            </td><td>0.0140027928485108                             </td><td>688058                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 3                                                   & 0.0102925974473447                                  & 0                                                   & 0.00658240204617865                                 & 0.0140027928485108                                  & 688058                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 3                                               | 0.0102925974473447                              | 0                                               | 0.00658240204617865                             | 0.0140027928485108                              | 688058                                          | rider/date/commute [first stop prefered riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                model OLS Estimate       BS p-value\n",
       "post_hov:IsRouteSeattle_10_ride 3     0.0102925974473447 0         \n",
       "                                CI lower            CI higher          N     \n",
       "post_hov:IsRouteSeattle_10_ride 0.00658240204617865 0.0140027928485108 688058\n",
       "                                granularity                                    \n",
       "post_hov:IsRouteSeattle_10_ride rider/date/commute [first stop prefered riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"In Progress...\")\n",
    "(table3_model3 = fit_ridership_logit_models(data = commute_ride_data[first_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\" ),\n",
    "                        model=3,\n",
    "                        granularity=\"rider/date/commute [first stop prefered riders]\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-04 05:24:58Starting the base glm (OLS) model...at 0.09\n",
      "Finished the base glm (OLS) model... in 2.051 seconds\n",
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "6.657232e-03 9.843061e-04 6.763376e+00 1.348820e-11 \n",
      "Finished the summary in 0.73 seconds\n",
      "Starting the wild bootstraps...at 2.091\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704122946\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results........ Completed.\n",
      "Finished wild bootstraps in 1.406 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>4                                             </td><td>0.00665723159617296                           </td><td>0.011988011988012                             </td><td>0.00158960117889512                           </td><td>0.0117248620134508                            </td><td>1068360                                       </td><td>rider/date/commute [last stop prefered riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 4                                                  & 0.00665723159617296                                & 0.011988011988012                                  & 0.00158960117889512                                & 0.0117248620134508                                 & 1068360                                            & rider/date/commute {[}last stop prefered riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 4                                              | 0.00665723159617296                            | 0.011988011988012                              | 0.00158960117889512                            | 0.0117248620134508                             | 1068360                                        | rider/date/commute [last stop prefered riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                model OLS Estimate        BS p-value       \n",
       "post_hov:IsRouteSeattle_10_ride 4     0.00665723159617296 0.011988011988012\n",
       "                                CI lower            CI higher          N      \n",
       "post_hov:IsRouteSeattle_10_ride 0.00158960117889512 0.0117248620134508 1068360\n",
       "                                granularity                                   \n",
       "post_hov:IsRouteSeattle_10_ride rider/date/commute [last stop prefered riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"In Progress...\")\n",
    "(table3_model4 = fit_ridership_logit_models(data = commute_ride_data[last_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                        model=4,\n",
    "                        granularity=\"rider/date/commute [last stop prefered riders]\"))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-04 06:51:25Starting the base glm (OLS) model...at 0.076\n",
      "Finished the base glm (OLS) model... in 23.975 seconds\n",
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "   Estimate  Std. Error     t value    Pr(>|t|) \n",
      "0.003878981 0.001262105 3.073422439 0.002116262 \n",
      "Finished the summary in 0.491 seconds\n",
      "Starting the wild bootstraps...at 25.312\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704135253\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished wild bootstraps in 54.457 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>5                  </td><td>0.00387898064639818</td><td>0.00499500499500505</td><td>0.00149512122891611</td><td>0.00626284006388025</td><td>759650             </td><td>ride/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 5                   & 0.00387898064639818 & 0.00499500499500505 & 0.00149512122891611 & 0.00626284006388025 & 759650              & ride/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 5                   | 0.00387898064639818 | 0.00499500499500505 | 0.00149512122891611 | 0.00626284006388025 | 759650              | ride/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                model OLS Estimate        BS p-value         \n",
       "post_hov:IsRouteSeattle_10_ride 5     0.00387898064639818 0.00499500499500505\n",
       "                                CI lower            CI higher           N     \n",
       "post_hov:IsRouteSeattle_10_ride 0.00149512122891611 0.00626284006388025 759650\n",
       "                                granularity      \n",
       "post_hov:IsRouteSeattle_10_ride ride/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "cat(\"In Progress...\")\n",
    "(table3_model5 = fit_ridership_logit_models(data = commute_ride_data[date >= as.Date(\"2016-03-01\") & \n",
    "                                                        date < as.Date(\"2016-07-01\")],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_favorite_route\", \"f_commutes_since_last_ride\" ),\n",
    "                        model=5,\n",
    "                        granularity=\"ride/date/commute\"))\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Table 3 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>1                                              </td><td>0.00818332646780441                            </td><td>0.000999000999000965                           </td><td>0.00408485239977426                            </td><td>0.0122818005358346                             </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:post_hov</th><td>2                                              </td><td>0.00811883641669418                            </td><td>0.0309690309690309                             </td><td>0.000844313316093389                           </td><td>0.015393359517295                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                                              </td><td>0.000210995677427104                           </td><td>0.929070929070929                              </td><td>-0.00618521170005434                           </td><td>0.00660720305490855                            </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:IsRouteSeattle_10_ride</th><td>2                                              </td><td>0.00850134229045719                            </td><td>0.0179820179820179                             </td><td>0.00159615757794212                            </td><td>0.0154065270029723                             </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:post_hov</th><td>2                                              </td><td>0.00224919071823332                            </td><td>0.46953046953047                               </td><td>-0.00455513135967938                           </td><td>0.00905351279614601                            </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride:IsRouteSeattle_10_ride:post_hov</th><td>2                                              </td><td>0.000255069378147556                           </td><td>0.942057942057942                              </td><td>-0.0071018605895833                            </td><td>0.00761199934587842                            </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>3                                              </td><td>0.0102925974473447                             </td><td>0                                              </td><td>0.00658240204617865                            </td><td>0.0140027928485108                             </td><td>688058                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>4                                              </td><td>0.00665723159617296                            </td><td>0.011988011988012                              </td><td>0.00158960117889512                            </td><td>0.0117248620134508                             </td><td>1068360                                        </td><td>rider/date/commute [last stop prefered riders] </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>5                                              </td><td>0.00387898064639818                            </td><td>0.00499500499500505                            </td><td>0.00149512122891611                            </td><td>0.00626284006388025                            </td><td>759650                                         </td><td>ride/date/commute                              </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 1                                               & 0.00818332646780441                             & 0.000999000999000965                            & 0.00408485239977426                             & 0.0122818005358346                              & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tIsRouteSeattle\\_10\\_ride:post\\_hov & 2                                               & 0.00811883641669418                             & 0.0309690309690309                              & 0.000844313316093389                            & 0.015393359517295                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                                               & 0.000210995677427104                            & 0.929070929070929                               & -0.00618521170005434                            & 0.00660720305490855                             & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride:IsRouteSeattle\\_10\\_ride & 2                                               & 0.00850134229045719                             & 0.0179820179820179                              & 0.00159615757794212                             & 0.0154065270029723                              & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride:post\\_hov & 2                                               & 0.00224919071823332                             & 0.46953046953047                                & -0.00455513135967938                            & 0.00905351279614601                             & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride:IsRouteSeattle\\_10\\_ride:post\\_hov & 2                                               & 0.000255069378147556                            & 0.942057942057942                               & -0.0071018605895833                             & 0.00761199934587842                             & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 3                                                   & 0.0102925974473447                                  & 0                                                   & 0.00658240204617865                                 & 0.0140027928485108                                  & 688058                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 4                                                   & 0.00665723159617296                                 & 0.011988011988012                                   & 0.00158960117889512                                 & 0.0117248620134508                                  & 1068360                                             & rider/date/commute {[}last stop prefered riders{]} \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 5                                               & 0.00387898064639818                             & 0.00499500499500505                             & 0.00149512122891611                             & 0.00626284006388025                             & 759650                                          & ride/date/commute                              \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| post_hov:IsRouteSeattle_10_ride | 1                                               | 0.00818332646780441                             | 0.000999000999000965                            | 0.00408485239977426                             | 0.0122818005358346                              | 1562314                                         | rider/date/commute                              |\n",
       "| IsRouteSeattle_10_ride:post_hov | 2                                               | 0.00811883641669418                             | 0.0309690309690309                              | 0.000844313316093389                            | 0.015393359517295                               | 1562314                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride | 2                                               | 0.000210995677427104                            | 0.929070929070929                               | -0.00618521170005434                            | 0.00660720305490855                             | 1562314                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride:IsRouteSeattle_10_ride | 2                                               | 0.00850134229045719                             | 0.0179820179820179                              | 0.00159615757794212                             | 0.0154065270029723                              | 1562314                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride:post_hov | 2                                               | 0.00224919071823332                             | 0.46953046953047                                | -0.00455513135967938                            | 0.00905351279614601                             | 1562314                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride:IsRouteSeattle_10_ride:post_hov | 2                                               | 0.000255069378147556                            | 0.942057942057942                               | -0.0071018605895833                             | 0.00761199934587842                             | 1562314                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride | 3                                               | 0.0102925974473447                              | 0                                               | 0.00658240204617865                             | 0.0140027928485108                              | 688058                                          | rider/date/commute [first stop prefered riders] |\n",
       "| post_hov:IsRouteSeattle_10_ride | 4                                               | 0.00665723159617296                             | 0.011988011988012                               | 0.00158960117889512                             | 0.0117248620134508                              | 1068360                                         | rider/date/commute [last stop prefered riders]  |\n",
       "| post_hov:IsRouteSeattle_10_ride | 5                                               | 0.00387898064639818                             | 0.00499500499500505                             | 0.00149512122891611                             | 0.00626284006388025                             | 759650                                          | ride/date/commute                               |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model OLS Estimate        \n",
       "post_hov:IsRouteSeattle_10_ride                 1     0.00818332646780441 \n",
       "IsRouteSeattle_10_ride:post_hov                 2     0.00811883641669418 \n",
       "is_peak_10_ride                                 2     0.000210995677427104\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          2     0.00850134229045719 \n",
       "is_peak_10_ride:post_hov                        2     0.00224919071823332 \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 2     0.000255069378147556\n",
       "post_hov:IsRouteSeattle_10_ride                 3     0.0102925974473447  \n",
       "post_hov:IsRouteSeattle_10_ride                 4     0.00665723159617296 \n",
       "post_hov:IsRouteSeattle_10_ride                 5     0.00387898064639818 \n",
       "                                                BS p-value          \n",
       "post_hov:IsRouteSeattle_10_ride                 0.000999000999000965\n",
       "IsRouteSeattle_10_ride:post_hov                 0.0309690309690309  \n",
       "is_peak_10_ride                                 0.929070929070929   \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.0179820179820179  \n",
       "is_peak_10_ride:post_hov                        0.46953046953047    \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.942057942057942   \n",
       "post_hov:IsRouteSeattle_10_ride                 0                   \n",
       "post_hov:IsRouteSeattle_10_ride                 0.011988011988012   \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00499500499500505 \n",
       "                                                CI lower            \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00408485239977426 \n",
       "IsRouteSeattle_10_ride:post_hov                 0.000844313316093389\n",
       "is_peak_10_ride                                 -0.00618521170005434\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.00159615757794212 \n",
       "is_peak_10_ride:post_hov                        -0.00455513135967938\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov -0.0071018605895833 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00658240204617865 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00158960117889512 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.00149512122891611 \n",
       "                                                CI higher           N      \n",
       "post_hov:IsRouteSeattle_10_ride                 0.0122818005358346  1562314\n",
       "IsRouteSeattle_10_ride:post_hov                 0.015393359517295   1562314\n",
       "is_peak_10_ride                                 0.00660720305490855 1562314\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          0.0154065270029723  1562314\n",
       "is_peak_10_ride:post_hov                        0.00905351279614601 1562314\n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov 0.00761199934587842 1562314\n",
       "post_hov:IsRouteSeattle_10_ride                 0.0140027928485108  688058 \n",
       "post_hov:IsRouteSeattle_10_ride                 0.0117248620134508  1068360\n",
       "post_hov:IsRouteSeattle_10_ride                 0.00626284006388025 759650 \n",
       "                                                granularity                                    \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute                             \n",
       "IsRouteSeattle_10_ride:post_hov                 rider/date/commute                             \n",
       "is_peak_10_ride                                 rider/date/commute                             \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride          rider/date/commute                             \n",
       "is_peak_10_ride:post_hov                        rider/date/commute                             \n",
       "is_peak_10_ride:IsRouteSeattle_10_ride:post_hov rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute [first stop prefered riders]\n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute [last stop prefered riders] \n",
       "post_hov:IsRouteSeattle_10_ride                 ride/date/commute                              "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "rbind( table3_model1,\n",
    "       table3_model2,\n",
    "       table3_model3,\n",
    "       table3_model4,\n",
    "       table3_model5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-03 21:19:57Starting the base glm (OLS) model...at 0.059\n",
      "Finished the base glm (OLS) model... in 4.352 seconds\n",
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "   Estimate  Std. Error     t value    Pr(>|t|) \n",
      "0.009015587 0.004457543 2.022546104 0.043122957 \n",
      "Finished the summary in 0.096 seconds\n",
      "Starting the wild bootstraps...at 5.693\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704042013\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.. Completed.\n",
      "Finished wild bootstraps in 3.228 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                                                </td><td>0.00901558706149908                              </td><td>0.674325674325674                                </td><td>-0.0277179351596873                              </td><td>0.0457491092826855                               </td><td>88994                                            </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                                     & 0.00901558706149908                                   & 0.674325674325674                                     & -0.0277179351596873                                   & 0.0457491092826855                                    & 88994                                                 & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                                                 | 0.00901558706149908                               | 0.674325674325674                                 | -0.0277179351596873                               | 0.0457491092826855                                | 88994                                             | rider/date/commute [Single Stop Preferred Riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                  model OLS Estimate        BS p-value       \n",
       "imputed_new_buses 1     0.00901558706149908 0.674325674325674\n",
       "                  CI lower            CI higher          N    \n",
       "imputed_new_buses -0.0277179351596873 0.0457491092826855 88994\n",
       "                  granularity                                      \n",
       "imputed_new_buses rider/date/commute [Single Stop Preferred Riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\")\n",
    "(T4_M1 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV) & (single_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Single Stop Preferred Riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-03 21:23:16Starting the base glm (OLS) model...at 0.068\n",
      "Finished the base glm (OLS) model... in 40.082 seconds\n",
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                         Estimate  Std. Error   t value\n",
      "imputed_new_buses                     0.001737459 0.001861185 0.9335231\n",
      "imputed_new_buses:single_stop_10_ride 0.005498788 0.002171814 2.5318869\n",
      "                                        Pr(>|t|)\n",
      "imputed_new_buses                     0.35055029\n",
      "imputed_new_buses:single_stop_10_ride 0.01134528\n",
      "Finished the summary in 0.552 seconds\n",
      "Starting the wild bootstraps...at 41.336\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704042517\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results...... Completed.\n",
      "Finished wild bootstraps in 21.698 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                   </td><td>0.00173745881407545 </td><td>0.818181818181818   </td><td>-0.0128758164255292 </td><td>0.0163507340536801  </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                   </td><td>0.00549878782776706 </td><td>0.16983016983017    </td><td>-0.00269272622222425</td><td>0.0136903018777584  </td><td>689102              </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                    & 0.00173745881407545  & 0.818181818181818    & -0.0128758164255292  & 0.0163507340536801   & 689102               & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                    & 0.00549878782776706  & 0.16983016983017     & -0.00269272622222425 & 0.0136903018777584   & 689102               & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                    | 0.00173745881407545  | 0.818181818181818    | -0.0128758164255292  | 0.0163507340536801   | 689102               | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                    | 0.00549878782776706  | 0.16983016983017     | -0.00269272622222425 | 0.0136903018777584   | 689102               | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                      model OLS Estimate       \n",
       "imputed_new_buses                     2     0.00173745881407545\n",
       "imputed_new_buses:single_stop_10_ride 2     0.00549878782776706\n",
       "                                      BS p-value        CI lower            \n",
       "imputed_new_buses                     0.818181818181818 -0.0128758164255292 \n",
       "imputed_new_buses:single_stop_10_ride 0.16983016983017  -0.00269272622222425\n",
       "                                      CI higher          N     \n",
       "imputed_new_buses                     0.0163507340536801 689102\n",
       "imputed_new_buses:single_stop_10_ride 0.0136903018777584 689102\n",
       "                                      granularity       \n",
       "imputed_new_buses                     rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\")\n",
    "(T4_M2 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:single_stop_10_ride\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\" ),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-03 21:45:39Starting the base glm (OLS) model...at 0.078\n",
      "Finished the base glm (OLS) model... in 41.995 seconds\n",
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                Estimate  Std. Error    t value\n",
      "imputed_new_buses                             0.05925864 0.065727359  0.9015826\n",
      "Is405North_10_ride:I405HOV                    0.05870747 0.008116622  7.2329931\n",
      "imputed_new_buses:I405HOV                    -0.05125314 0.065497055 -0.7825258\n",
      "imputed_new_buses:Is405North_10_ride          0.12690928 0.087552298  1.4495254\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV -0.15637832 0.087516154 -1.7868509\n",
      "                                                 Pr(>|t|)\n",
      "imputed_new_buses                            3.672790e-01\n",
      "Is405North_10_ride:I405HOV                   4.729508e-13\n",
      "imputed_new_buses:I405HOV                    4.339059e-01\n",
      "imputed_new_buses:Is405North_10_ride         1.471914e-01\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV 7.396202e-02\n",
      "Finished the summary in 0.468 seconds\n",
      "Starting the wild bootstraps...at 43.218\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704044744\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished wild bootstraps in 22.732 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                  </td><td>0.0592586406244381 </td><td>0.395604395604396  </td><td>-0.0679831137202049</td><td>0.186500394969081  </td><td>689102             </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                  </td><td>0.0587074673415004 </td><td>0                  </td><td>0.0240107625996032 </td><td>0.0934041720833976 </td><td>689102             </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                  </td><td>-0.0512531352488887</td><td>0.441558441558442  </td><td>-0.173965755208672 </td><td>0.0714594847108946 </td><td>689102             </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                  </td><td>0.126909278014275  </td><td>0.1998001998002    </td><td>-0.0548441553194129</td><td>0.308662711347963  </td><td>689102             </td><td>rider/date/commute </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                  </td><td>-0.156378320404112 </td><td>0.0769230769230769 </td><td>-0.330315101596113 </td><td>0.0175584607878899 </td><td>689102             </td><td>rider/date/commute </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                   & 0.0592586406244381  & 0.395604395604396   & -0.0679831137202049 & 0.186500394969081   & 689102              & rider/date/commute \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                   & 0.0587074673415004  & 0                   & 0.0240107625996032  & 0.0934041720833976  & 689102              & rider/date/commute \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                   & -0.0512531352488887 & 0.441558441558442   & -0.173965755208672  & 0.0714594847108946  & 689102              & rider/date/commute \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                   & 0.126909278014275   & 0.1998001998002     & -0.0548441553194129 & 0.308662711347963   & 689102              & rider/date/commute \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                   & -0.156378320404112  & 0.0769230769230769  & -0.330315101596113  & 0.0175584607878899  & 689102              & rider/date/commute \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                   | 0.0592586406244381  | 0.395604395604396   | -0.0679831137202049 | 0.186500394969081   | 689102              | rider/date/commute  |\n",
       "| Is405North_10_ride:I405HOV | 3                   | 0.0587074673415004  | 0                   | 0.0240107625996032  | 0.0934041720833976  | 689102              | rider/date/commute  |\n",
       "| imputed_new_buses:I405HOV | 3                   | -0.0512531352488887 | 0.441558441558442   | -0.173965755208672  | 0.0714594847108946  | 689102              | rider/date/commute  |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                   | 0.126909278014275   | 0.1998001998002     | -0.0548441553194129 | 0.308662711347963   | 689102              | rider/date/commute  |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                   | -0.156378320404112  | 0.0769230769230769  | -0.330315101596113  | 0.0175584607878899  | 689102              | rider/date/commute  |\n",
       "\n"
      ],
      "text/plain": [
       "                                             model OLS Estimate       \n",
       "imputed_new_buses                            3     0.0592586406244381 \n",
       "Is405North_10_ride:I405HOV                   3     0.0587074673415004 \n",
       "imputed_new_buses:I405HOV                    3     -0.0512531352488887\n",
       "imputed_new_buses:Is405North_10_ride         3     0.126909278014275  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 3     -0.156378320404112 \n",
       "                                             BS p-value        \n",
       "imputed_new_buses                            0.395604395604396 \n",
       "Is405North_10_ride:I405HOV                   0                 \n",
       "imputed_new_buses:I405HOV                    0.441558441558442 \n",
       "imputed_new_buses:Is405North_10_ride         0.1998001998002   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.0769230769230769\n",
       "                                             CI lower           \n",
       "imputed_new_buses                            -0.0679831137202049\n",
       "Is405North_10_ride:I405HOV                   0.0240107625996032 \n",
       "imputed_new_buses:I405HOV                    -0.173965755208672 \n",
       "imputed_new_buses:Is405North_10_ride         -0.0548441553194129\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV -0.330315101596113 \n",
       "                                             CI higher          N     \n",
       "imputed_new_buses                            0.186500394969081  689102\n",
       "Is405North_10_ride:I405HOV                   0.0934041720833976 689102\n",
       "imputed_new_buses:I405HOV                    0.0714594847108946 689102\n",
       "imputed_new_buses:Is405North_10_ride         0.308662711347963  689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.0175584607878899 689102\n",
       "                                             granularity       \n",
       "imputed_new_buses                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:I405HOV                    rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride         rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\")\n",
    "(T4_M3 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-03 22:09:05Starting the base glm (OLS) model...at 0.078\n",
      "Finished the base glm (OLS) model... in 43.942 seconds\n",
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                    Estimate  Std. Error\n",
      "imputed_new_buses                               0.0080381633 0.002033987\n",
      "imputed_new_buses:single_stop_10_ride          -0.0004127913 0.002720499\n",
      "Is405North_10_ride:I405HOV                      0.0414742547 0.006451958\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -0.0295707141 0.003591242\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV  0.0156682822 0.004039997\n",
      "                                                  t value     Pr(>|t|)\n",
      "imputed_new_buses                               3.9519241 7.753307e-05\n",
      "imputed_new_buses:single_stop_10_ride          -0.1517337 8.793970e-01\n",
      "Is405North_10_ride:I405HOV                      6.4281656 1.292369e-10\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -8.2341192 1.811944e-16\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV  3.8782909 1.052026e-04\n",
      "Finished the summary in 0.468 seconds\n",
      "Starting the wild bootstraps...at 45.269\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704051114\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results... Completed.\n",
      "Finished wild bootstraps in 21.843 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                    </td><td>0.00803816326845027  </td><td>0.290709290709291    </td><td>-0.00767066550312311 </td><td>0.0237469920400236   </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                    </td><td>-0.000412791310470248</td><td>0.976023976023976    </td><td>-0.024727336474957   </td><td>0.0239017538540165   </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                    </td><td>0.0414742546545521   </td><td>0.0939060939060939   </td><td>-0.00663494289057705 </td><td>0.0895834521996813   </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                    </td><td>-0.0295707141315858  </td><td>0.00199800199800204  </td><td>-0.0513297277413901  </td><td>-0.00781170052178158 </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                    </td><td>0.0156682821909522   </td><td>0.123876123876124    </td><td>-0.00378223631669364 </td><td>0.035118800698598    </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                     & 0.00803816326845027   & 0.290709290709291     & -0.00767066550312311  & 0.0237469920400236    & 689102                & rider/date/commute   \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                     & -0.000412791310470248 & 0.976023976023976     & -0.024727336474957    & 0.0239017538540165    & 689102                & rider/date/commute   \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                     & 0.0414742546545521    & 0.0939060939060939    & -0.00663494289057705  & 0.0895834521996813    & 689102                & rider/date/commute   \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                     & -0.0295707141315858   & 0.00199800199800204   & -0.0513297277413901   & -0.00781170052178158  & 689102                & rider/date/commute   \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                     & 0.0156682821909522    & 0.123876123876124     & -0.00378223631669364  & 0.035118800698598     & 689102                & rider/date/commute   \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                     | 0.00803816326845027   | 0.290709290709291     | -0.00767066550312311  | 0.0237469920400236    | 689102                | rider/date/commute    |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                     | -0.000412791310470248 | 0.976023976023976     | -0.024727336474957    | 0.0239017538540165    | 689102                | rider/date/commute    |\n",
       "| Is405North_10_ride:I405HOV | 4                     | 0.0414742546545521    | 0.0939060939060939    | -0.00663494289057705  | 0.0895834521996813    | 689102                | rider/date/commute    |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                     | -0.0295707141315858   | 0.00199800199800204   | -0.0513297277413901   | -0.00781170052178158  | 689102                | rider/date/commute    |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                     | 0.0156682821909522    | 0.123876123876124     | -0.00378223631669364  | 0.035118800698598     | 689102                | rider/date/commute    |\n",
       "\n"
      ],
      "text/plain": [
       "                                               model OLS Estimate         \n",
       "imputed_new_buses                              4     0.00803816326845027  \n",
       "imputed_new_buses:single_stop_10_ride          4     -0.000412791310470248\n",
       "Is405North_10_ride:I405HOV                     4     0.0414742546545521   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   4     -0.0295707141315858  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 4     0.0156682821909522   \n",
       "                                               BS p-value         \n",
       "imputed_new_buses                              0.290709290709291  \n",
       "imputed_new_buses:single_stop_10_ride          0.976023976023976  \n",
       "Is405North_10_ride:I405HOV                     0.0939060939060939 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.00199800199800204\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.123876123876124  \n",
       "                                               CI lower            \n",
       "imputed_new_buses                              -0.00767066550312311\n",
       "imputed_new_buses:single_stop_10_ride          -0.024727336474957  \n",
       "Is405North_10_ride:I405HOV                     -0.00663494289057705\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   -0.0513297277413901 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV -0.00378223631669364\n",
       "                                               CI higher            N     \n",
       "imputed_new_buses                              0.0237469920400236   689102\n",
       "imputed_new_buses:single_stop_10_ride          0.0239017538540165   689102\n",
       "Is405North_10_ride:I405HOV                     0.0895834521996813   689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   -0.00781170052178158 689102\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.035118800698598    689102\n",
       "                                               granularity       \n",
       "imputed_new_buses                              rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride          rider/date/commute\n",
       "Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\")\n",
    "(T4_M4 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "In Progress...Starting at 2020-07-03 22:31:41Starting the base glm (OLS) model...at 0.07\n",
      "Finished the base glm (OLS) model... in 43.17 seconds\n",
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                                     Estimate\n",
      "imputed_new_buses                                                 0.007666990\n",
      "imputed_new_buses:single_stop_10_ride                             0.001589376\n",
      "Is405North_10_ride:I405HOV                                        0.036866859\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.023999800\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    0.037855361\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.026887264\n",
      "                                                                  Std. Error\n",
      "imputed_new_buses                                                0.002039003\n",
      "imputed_new_buses:single_stop_10_ride                            0.002827812\n",
      "Is405North_10_ride:I405HOV                                       0.006691841\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     0.004184138\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.009457541\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.010362759\n",
      "                                                                    t value\n",
      "imputed_new_buses                                                 3.7601652\n",
      "imputed_new_buses:single_stop_10_ride                             0.5620514\n",
      "Is405North_10_ride:I405HOV                                        5.5092249\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     -5.7359002\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    4.0026644\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -2.5946049\n",
      "                                                                     Pr(>|t|)\n",
      "imputed_new_buses                                                1.698152e-04\n",
      "imputed_new_buses:single_stop_10_ride                            5.740812e-01\n",
      "Is405North_10_ride:I405HOV                                       3.605455e-08\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     9.703617e-09\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   6.263968e-05\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 9.470172e-03\n",
      "Finished the summary in 0.531 seconds\n",
      "Starting the wild bootstraps...at 44.426\n",
      "\n",
      " \n",
      " Note: null not imposed (factor variables are present). \n",
      " \n",
      "else... \n",
      "Wild Cluster bootstrapping w/o imposing null... \n",
      "================================================================================\n",
      "Id: job20200704053346\n",
      "chunkSize: 1\n",
      "enableCloudCombine: TRUE\n",
      "errorHandling: stop\n",
      "wait: TRUE\n",
      "autoDeleteJob: TRUE\n",
      "================================================================================\n",
      "Submitting tasks (1001/1001)\n",
      "Submitting merge task. . .\n",
      "Waiting for tasks to complete. . .\n",
      "| Progress: 100.00% (1001/1001) | Running: 0 | Queued: 0 | Completed: 1001 | Failed: 0 |\n",
      "Tasks have completed. Merging results.... Completed.\n",
      "Finished wild bootstraps in 22.739 seconds\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                    </td><td>0.00766698968617267  </td><td>0.31968031968032     </td><td>-0.00813384998638649 </td><td>0.0234678293587318   </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                    </td><td>0.00158937561994611  </td><td>0.828171828171828    </td><td>-0.018406648052493   </td><td>0.0215853992923852   </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                    </td><td>0.0368668588044216   </td><td>0.147852147852148    </td><td>-0.0280968319798818  </td><td>0.101830549588725    </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                    </td><td>-0.0239997996594213  </td><td>0.044955044955045    </td><td>-0.0474982109470028  </td><td>-0.000501388371839804</td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                    </td><td>0.0378553614506872   </td><td>0.543456543456543    </td><td>-0.0639337593253137  </td><td>0.139644482226688    </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                    </td><td>-0.0268872642205655  </td><td>0.694305694305694    </td><td>-0.155683407139794   </td><td>0.101908878698663    </td><td>689102               </td><td>rider/date/commute   </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 5                     & 0.00766698968617267   & 0.31968031968032      & -0.00813384998638649  & 0.0234678293587318    & 689102                & rider/date/commute   \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                     & 0.00158937561994611   & 0.828171828171828     & -0.018406648052493    & 0.0215853992923852    & 689102                & rider/date/commute   \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                     & 0.0368668588044216    & 0.147852147852148     & -0.0280968319798818   & 0.101830549588725     & 689102                & rider/date/commute   \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                     & -0.0239997996594213   & 0.044955044955045     & -0.0474982109470028   & -0.000501388371839804 & 689102                & rider/date/commute   \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                     & 0.0378553614506872    & 0.543456543456543     & -0.0639337593253137   & 0.139644482226688     & 689102                & rider/date/commute   \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                     & -0.0268872642205655   & 0.694305694305694     & -0.155683407139794    & 0.101908878698663     & 689102                & rider/date/commute   \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 5                     | 0.00766698968617267   | 0.31968031968032      | -0.00813384998638649  | 0.0234678293587318    | 689102                | rider/date/commute    |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                     | 0.00158937561994611   | 0.828171828171828     | -0.018406648052493    | 0.0215853992923852    | 689102                | rider/date/commute    |\n",
       "| Is405North_10_ride:I405HOV | 5                     | 0.0368668588044216    | 0.147852147852148     | -0.0280968319798818   | 0.101830549588725     | 689102                | rider/date/commute    |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                     | -0.0239997996594213   | 0.044955044955045     | -0.0474982109470028   | -0.000501388371839804 | 689102                | rider/date/commute    |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                     | 0.0378553614506872    | 0.543456543456543     | -0.0639337593253137   | 0.139644482226688     | 689102                | rider/date/commute    |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                     | -0.0268872642205655   | 0.694305694305694     | -0.155683407139794    | 0.101908878698663     | 689102                | rider/date/commute    |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 OLS Estimate       \n",
       "imputed_new_buses                                                0.00766698968617267\n",
       "imputed_new_buses:single_stop_10_ride                            0.00158937561994611\n",
       "Is405North_10_ride:I405HOV                                       0.0368668588044216 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0239997996594213\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0378553614506872 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.0268872642205655\n",
       "                                                                 BS p-value       \n",
       "imputed_new_buses                                                0.31968031968032 \n",
       "imputed_new_buses:single_stop_10_ride                            0.828171828171828\n",
       "Is405North_10_ride:I405HOV                                       0.147852147852148\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.044955044955045\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.543456543456543\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.694305694305694\n",
       "                                                                 CI lower            \n",
       "imputed_new_buses                                                -0.00813384998638649\n",
       "imputed_new_buses:single_stop_10_ride                            -0.018406648052493  \n",
       "Is405North_10_ride:I405HOV                                       -0.0280968319798818 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0474982109470028 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.0639337593253137 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.155683407139794  \n",
       "                                                                 CI higher            \n",
       "imputed_new_buses                                                0.0234678293587318   \n",
       "imputed_new_buses:single_stop_10_ride                            0.0215853992923852   \n",
       "Is405North_10_ride:I405HOV                                       0.101830549588725    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.000501388371839804\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.139644482226688    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.101908878698663    \n",
       "                                                                 N     \n",
       "imputed_new_buses                                                689102\n",
       "imputed_new_buses:single_stop_10_ride                            689102\n",
       "Is405North_10_ride:I405HOV                                       689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     689102\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   689102\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 689102\n",
       "                                                                 granularity       \n",
       "imputed_new_buses                                                rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cat(\"In Progress...\")\n",
    "(T4_M5 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 4 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>OLS Estimate</th><th scope=col>BS p-value</th><th scope=col>CI lower</th><th scope=col>CI higher</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>1                                                </td><td>0.00901558706149908                              </td><td>0.674325674325674                                </td><td>-0.0277179351596873                              </td><td>0.0457491092826855                               </td><td>88994                                            </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                </td><td>0.00173745881407545                              </td><td>0.818181818181818                                </td><td>-0.0128758164255292                              </td><td>0.0163507340536801                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                                                </td><td>0.00549878782776706                              </td><td>0.16983016983017                                 </td><td>-0.00269272622222425                             </td><td>0.0136903018777584                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                </td><td>0.0592586406244381                               </td><td>0.395604395604396                                </td><td>-0.0679831137202049                              </td><td>0.186500394969081                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                                                </td><td>0.0587074673415004                               </td><td>0                                                </td><td>0.0240107625996032                               </td><td>0.0934041720833976                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                                                </td><td>-0.0512531352488887                              </td><td>0.441558441558442                                </td><td>-0.173965755208672                               </td><td>0.0714594847108946                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                                                </td><td>0.126909278014275                                </td><td>0.1998001998002                                  </td><td>-0.0548441553194129                              </td><td>0.308662711347963                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                                                </td><td>-0.156378320404112                               </td><td>0.0769230769230769                               </td><td>-0.330315101596113                               </td><td>0.0175584607878899                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                </td><td>0.00803816326845027                              </td><td>0.290709290709291                                </td><td>-0.00767066550312311                             </td><td>0.0237469920400236                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                                                </td><td>-0.000412791310470248                            </td><td>0.976023976023976                                </td><td>-0.024727336474957                               </td><td>0.0239017538540165                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                                                </td><td>0.0414742546545521                               </td><td>0.0939060939060939                               </td><td>-0.00663494289057705                             </td><td>0.0895834521996813                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.0295707141315858                              </td><td>0.00199800199800204                              </td><td>-0.0513297277413901                              </td><td>-0.00781170052178158                             </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>0.0156682821909522                               </td><td>0.123876123876124                                </td><td>-0.00378223631669364                             </td><td>0.035118800698598                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                </td><td>0.00766698968617267                              </td><td>0.31968031968032                                 </td><td>-0.00813384998638649                             </td><td>0.0234678293587318                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                                                </td><td>0.00158937561994611                              </td><td>0.828171828171828                                </td><td>-0.018406648052493                               </td><td>0.0215853992923852                               </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.0368668588044216                               </td><td>0.147852147852148                                </td><td>-0.0280968319798818                              </td><td>0.101830549588725                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0239997996594213                              </td><td>0.044955044955045                                </td><td>-0.0474982109470028                              </td><td>-0.000501388371839804                            </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.0378553614506872                               </td><td>0.543456543456543                                </td><td>-0.0639337593253137                              </td><td>0.139644482226688                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0268872642205655                              </td><td>0.694305694305694                                </td><td>-0.155683407139794                               </td><td>0.101908878698663                                </td><td>689102                                           </td><td>rider/date/commute                               </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & OLS Estimate & BS p-value & CI lower & CI higher & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 1                                                     & 0.00901558706149908                                   & 0.674325674325674                                     & -0.0277179351596873                                   & 0.0457491092826855                                    & 88994                                                 & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\timputed\\_new\\_buses & 2                                                 & 0.00173745881407545                               & 0.818181818181818                                 & -0.0128758164255292                               & 0.0163507340536801                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                                                 & 0.00549878782776706                               & 0.16983016983017                                  & -0.00269272622222425                              & 0.0136903018777584                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 3                                                 & 0.0592586406244381                                & 0.395604395604396                                 & -0.0679831137202049                               & 0.186500394969081                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                                                 & 0.0587074673415004                                & 0                                                 & 0.0240107625996032                                & 0.0934041720833976                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                                                 & -0.0512531352488887                               & 0.441558441558442                                 & -0.173965755208672                                & 0.0714594847108946                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                                                 & 0.126909278014275                                 & 0.1998001998002                                   & -0.0548441553194129                               & 0.308662711347963                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                                                 & -0.156378320404112                                & 0.0769230769230769                                & -0.330315101596113                                & 0.0175584607878899                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 4                                                 & 0.00803816326845027                               & 0.290709290709291                                 & -0.00767066550312311                              & 0.0237469920400236                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                                                 & -0.000412791310470248                             & 0.976023976023976                                 & -0.024727336474957                                & 0.0239017538540165                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                                                 & 0.0414742546545521                                & 0.0939060939060939                                & -0.00663494289057705                              & 0.0895834521996813                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.0295707141315858                               & 0.00199800199800204                               & -0.0513297277413901                               & -0.00781170052178158                              & 689102                                            & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                                                 & 0.0156682821909522                                & 0.123876123876124                                 & -0.00378223631669364                              & 0.035118800698598                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 5                                                 & 0.00766698968617267                               & 0.31968031968032                                  & -0.00813384998638649                              & 0.0234678293587318                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                                                 & 0.00158937561994611                               & 0.828171828171828                                 & -0.018406648052493                                & 0.0215853992923852                                & 689102                                            & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                                                 & 0.0368668588044216                                & 0.147852147852148                                 & -0.0280968319798818                               & 0.101830549588725                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.0239997996594213                               & 0.044955044955045                                 & -0.0474982109470028                               & -0.000501388371839804                             & 689102                                            & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & 0.0378553614506872                                & 0.543456543456543                                 & -0.0639337593253137                               & 0.139644482226688                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.0268872642205655                               & 0.694305694305694                                 & -0.155683407139794                                & 0.101908878698663                                 & 689102                                            & rider/date/commute                               \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | OLS Estimate | BS p-value | CI lower | CI higher | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 1                                                 | 0.00901558706149908                               | 0.674325674325674                                 | -0.0277179351596873                               | 0.0457491092826855                                | 88994                                             | rider/date/commute [Single Stop Preferred Riders] |\n",
       "| imputed_new_buses | 2                                                 | 0.00173745881407545                               | 0.818181818181818                                 | -0.0128758164255292                               | 0.0163507340536801                                | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                                                 | 0.00549878782776706                               | 0.16983016983017                                  | -0.00269272622222425                              | 0.0136903018777584                                | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses | 3                                                 | 0.0592586406244381                                | 0.395604395604396                                 | -0.0679831137202049                               | 0.186500394969081                                 | 689102                                            | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 3                                                 | 0.0587074673415004                                | 0                                                 | 0.0240107625996032                                | 0.0934041720833976                                | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:I405HOV | 3                                                 | -0.0512531352488887                               | 0.441558441558442                                 | -0.173965755208672                                | 0.0714594847108946                                | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                                                 | 0.126909278014275                                 | 0.1998001998002                                   | -0.0548441553194129                               | 0.308662711347963                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                                                 | -0.156378320404112                                | 0.0769230769230769                                | -0.330315101596113                                | 0.0175584607878899                                | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses | 4                                                 | 0.00803816326845027                               | 0.290709290709291                                 | -0.00767066550312311                              | 0.0237469920400236                                | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                                                 | -0.000412791310470248                             | 0.976023976023976                                 | -0.024727336474957                                | 0.0239017538540165                                | 689102                                            | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 4                                                 | 0.0414742546545521                                | 0.0939060939060939                                | -0.00663494289057705                              | 0.0895834521996813                                | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                                                 | -0.0295707141315858                               | 0.00199800199800204                               | -0.0513297277413901                               | -0.00781170052178158                              | 689102                                            | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                                                 | 0.0156682821909522                                | 0.123876123876124                                 | -0.00378223631669364                              | 0.035118800698598                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses | 5                                                 | 0.00766698968617267                               | 0.31968031968032                                  | -0.00813384998638649                              | 0.0234678293587318                                | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                                                 | 0.00158937561994611                               | 0.828171828171828                                 | -0.018406648052493                                | 0.0215853992923852                                | 689102                                            | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 5                                                 | 0.0368668588044216                                | 0.147852147852148                                 | -0.0280968319798818                               | 0.101830549588725                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                                                 | -0.0239997996594213                               | 0.044955044955045                                 | -0.0474982109470028                               | -0.000501388371839804                             | 689102                                            | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | 0.0378553614506872                                | 0.543456543456543                                 | -0.0639337593253137                               | 0.139644482226688                                 | 689102                                            | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | -0.0268872642205655                               | 0.694305694305694                                 | -0.155683407139794                                | 0.101908878698663                                 | 689102                                            | rider/date/commute                                |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                1    \n",
       "imputed_new_buses                                                2    \n",
       "imputed_new_buses:single_stop_10_ride                            2    \n",
       "imputed_new_buses                                                3    \n",
       "Is405North_10_ride:I405HOV                                       3    \n",
       "imputed_new_buses:I405HOV                                        3    \n",
       "imputed_new_buses:Is405North_10_ride                             3    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     3    \n",
       "imputed_new_buses                                                4    \n",
       "imputed_new_buses:single_stop_10_ride                            4    \n",
       "Is405North_10_ride:I405HOV                                       4    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     4    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   4    \n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 OLS Estimate         \n",
       "imputed_new_buses                                                0.00901558706149908  \n",
       "imputed_new_buses                                                0.00173745881407545  \n",
       "imputed_new_buses:single_stop_10_ride                            0.00549878782776706  \n",
       "imputed_new_buses                                                0.0592586406244381   \n",
       "Is405North_10_ride:I405HOV                                       0.0587074673415004   \n",
       "imputed_new_buses:I405HOV                                        -0.0512531352488887  \n",
       "imputed_new_buses:Is405North_10_ride                             0.126909278014275    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.156378320404112   \n",
       "imputed_new_buses                                                0.00803816326845027  \n",
       "imputed_new_buses:single_stop_10_ride                            -0.000412791310470248\n",
       "Is405North_10_ride:I405HOV                                       0.0414742546545521   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0295707141315858  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0156682821909522   \n",
       "imputed_new_buses                                                0.00766698968617267  \n",
       "imputed_new_buses:single_stop_10_ride                            0.00158937561994611  \n",
       "Is405North_10_ride:I405HOV                                       0.0368668588044216   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0239997996594213  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0378553614506872   \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.0268872642205655  \n",
       "                                                                 BS p-value         \n",
       "imputed_new_buses                                                0.674325674325674  \n",
       "imputed_new_buses                                                0.818181818181818  \n",
       "imputed_new_buses:single_stop_10_ride                            0.16983016983017   \n",
       "imputed_new_buses                                                0.395604395604396  \n",
       "Is405North_10_ride:I405HOV                                       0                  \n",
       "imputed_new_buses:I405HOV                                        0.441558441558442  \n",
       "imputed_new_buses:Is405North_10_ride                             0.1998001998002    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0769230769230769 \n",
       "imputed_new_buses                                                0.290709290709291  \n",
       "imputed_new_buses:single_stop_10_ride                            0.976023976023976  \n",
       "Is405North_10_ride:I405HOV                                       0.0939060939060939 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.00199800199800204\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.123876123876124  \n",
       "imputed_new_buses                                                0.31968031968032   \n",
       "imputed_new_buses:single_stop_10_ride                            0.828171828171828  \n",
       "Is405North_10_ride:I405HOV                                       0.147852147852148  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.044955044955045  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.543456543456543  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.694305694305694  \n",
       "                                                                 CI lower            \n",
       "imputed_new_buses                                                -0.0277179351596873 \n",
       "imputed_new_buses                                                -0.0128758164255292 \n",
       "imputed_new_buses:single_stop_10_ride                            -0.00269272622222425\n",
       "imputed_new_buses                                                -0.0679831137202049 \n",
       "Is405North_10_ride:I405HOV                                       0.0240107625996032  \n",
       "imputed_new_buses:I405HOV                                        -0.173965755208672  \n",
       "imputed_new_buses:Is405North_10_ride                             -0.0548441553194129 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.330315101596113  \n",
       "imputed_new_buses                                                -0.00767066550312311\n",
       "imputed_new_buses:single_stop_10_ride                            -0.024727336474957  \n",
       "Is405North_10_ride:I405HOV                                       -0.00663494289057705\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0513297277413901 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.00378223631669364\n",
       "imputed_new_buses                                                -0.00813384998638649\n",
       "imputed_new_buses:single_stop_10_ride                            -0.018406648052493  \n",
       "Is405North_10_ride:I405HOV                                       -0.0280968319798818 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0474982109470028 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.0639337593253137 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.155683407139794  \n",
       "                                                                 CI higher            \n",
       "imputed_new_buses                                                0.0457491092826855   \n",
       "imputed_new_buses                                                0.0163507340536801   \n",
       "imputed_new_buses:single_stop_10_ride                            0.0136903018777584   \n",
       "imputed_new_buses                                                0.186500394969081    \n",
       "Is405North_10_ride:I405HOV                                       0.0934041720833976   \n",
       "imputed_new_buses:I405HOV                                        0.0714594847108946   \n",
       "imputed_new_buses:Is405North_10_ride                             0.308662711347963    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0175584607878899   \n",
       "imputed_new_buses                                                0.0237469920400236   \n",
       "imputed_new_buses:single_stop_10_ride                            0.0239017538540165   \n",
       "Is405North_10_ride:I405HOV                                       0.0895834521996813   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.00781170052178158 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.035118800698598    \n",
       "imputed_new_buses                                                0.0234678293587318   \n",
       "imputed_new_buses:single_stop_10_ride                            0.0215853992923852   \n",
       "Is405North_10_ride:I405HOV                                       0.101830549588725    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.000501388371839804\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.139644482226688    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.101908878698663    \n",
       "                                                                 N     \n",
       "imputed_new_buses                                                88994 \n",
       "imputed_new_buses                                                689102\n",
       "imputed_new_buses:single_stop_10_ride                            689102\n",
       "imputed_new_buses                                                689102\n",
       "Is405North_10_ride:I405HOV                                       689102\n",
       "imputed_new_buses:I405HOV                                        689102\n",
       "imputed_new_buses:Is405North_10_ride                             689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     689102\n",
       "imputed_new_buses                                                689102\n",
       "imputed_new_buses:single_stop_10_ride                            689102\n",
       "Is405North_10_ride:I405HOV                                       689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     689102\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   689102\n",
       "imputed_new_buses                                                689102\n",
       "imputed_new_buses:single_stop_10_ride                            689102\n",
       "Is405North_10_ride:I405HOV                                       689102\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     689102\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   689102\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 689102\n",
       "                                                                 granularity                                      \n",
       "imputed_new_buses                                                rider/date/commute [Single Stop Preferred Riders]\n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:I405HOV                                        rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride                             rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute                               "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(TABLE_4 <- rbind(T4_M1,T4_M2,T4_M3,T4_M4,T4_M5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DONE"
     ]
    }
   ],
   "source": [
    "cat(\"DONE\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
